package wuuxiang.crm;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ElectronicQuanAction {

	public static void main(String[] args) {
		System.setProperty("webdriver.firefox.bin", "D:/Firefox.exe");
		WebDriver driver = new FirefoxDriver();
		driver.manage().window().maximize();
		Base loginShop = new Base(driver);
		loginShop.login("tcsl", "123456", "1001", "14235");

		// 定位左边frame
		WebElement zbk = driver.findElement(By.name("leftFrame"));
		System.out.println(zbk);
		driver.switchTo().frame(zbk);

		ElectronicQuanElement q = new ElectronicQuanElement(driver);
		q.findLeft();

		// 还原frame
		driver.switchTo().defaultContent();
		// 定位右边frame
		WebElement ybk = driver.findElement(By.name("mainFrame"));
		System.out.println(ybk);
		driver.switchTo().frame(ybk);

		WebElement ybk1 = driver
				.findElement(By.xpath("//*[contains(@src,'/shop/electroniccoupons/ElectroniccouponsAction.a')]"));
		System.out.println(ybk1);
		driver.switchTo().frame(ybk1);

		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

		// 点击增加按钮
		q.findRight();

		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

		// 填写增加页面信息
		q.insertpage("忐忑", "15", "1000");

		// 传值
		((JavascriptExecutor) driver).executeScript("document.getElementById('kindBeginDay').value='2016-09-06'");
		((JavascriptExecutor) driver).executeScript("document.getElementById('kindEndDay').value='2017-09-06'");

		// 保存
		q.qsave();

		// 修改
		q.d("你好");

		// 查询
		q.e("0540");

		// 删除
		q.f();

		try {
			Thread.sleep(1000);
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}

		Alert javascriptConfirm = driver.switchTo().alert();
		javascriptConfirm.accept();

	}
}
